package string;

public class StringBuilderDemo {
    public static void main(String[] args) {
        StringBuilder builder1=new StringBuilder();//1  空字符串
        StringBuilder builder2=new StringBuilder("abc");//2  abc串
        //String和StringBuild厄尔互转
//        String str ="abc";
//        StringBuilder builder3=new StringBuilder(str);
//        String str2=builder3.toString();
        String str ="好好学习java";
        StringBuilder builder3=new StringBuilder(str);
        builder3.append(",为了找个好工作");//在末尾追加
        System.out.println(builder3);
        int start=builder3.indexOf("为");
        int end=builder3.lastIndexOf("作");
        builder3.replace(start,end,"就是为了改变世界");//替换部分内容（含头不含尾）
       System.out.println(builder3);

        builder3.delete(0,8);//删除部分内容（含头不含尾）
        System.out.println(builder3);

        builder3.insert(0,"活着");
        System.out.println(builder3);
    }
}
